﻿#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <iostream>

using namespace std;

void print_text(const TCHAR* text, int x, int y);

int main()
{
	int height = 600;
	int width = 800;
	int count = 0;
	initgraph(width, height); // Initialize painting canvas

	float radius = 20;
	float x = radius;
	float y = 50;
	float speed_y = 0;
	float speed_x = 5;
	//int num = height / speed;
	float g = 5;
	float resistance = 0.78;
	
	while (count < 10)
	{
		
		for (;;)
		{
			fillcircle(x, y, radius);
			TCHAR s[200];
			swprintf_s(s, _T("%2.f,%2.f,%2.f,%2.f,%2.f\n"), x, y, radius, speed_x, speed_y);
			print_text(s, 50, 30);

			Sleep(100);
			cleardevice();
			
			speed_x += 0;
			speed_y += g;
			x += speed_x;
			y += speed_y;
			
			
			if (y + radius >= height)
			{
				y = height - radius;
				speed_y = -speed_y * resistance;
				//speed = -1;
				//g = -g;
			}

			if (y <= radius)
			{
				y = radius;
				if (speed_y < 0)
				{
					speed_y = -speed_y;
					//speed = 1;
					//g = -g;
				}
			}
			if (x >= width - radius)
			{
				speed_x = 0;
				speed_y = 0;
			}
		}

		count++;
	}


	_getch();
	closegraph(); // Close canvas
	return 0;
}

void print_text(const TCHAR* text, int x, int y)
{
	settextstyle(40, 0, _T("楷体"));
	outtextxy(x, y, text);
}
